package com.atstudent.gmall.user.controller;

import com.atstudent.gmall.common.result.Result;
import com.atstudent.gmall.user.dto.UserLoginDto;
import com.atstudent.gmall.user.service.UserInfoService;
import com.atstudent.gmall.user.vo.UserLoginSuccessVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户登陆退出
 * @Author 薛有朋
 * @CreatDate 2025/3/26 21:58
 **/
@RestController
@RequestMapping(value = "/api/user/passport")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;


    /**
     * 用户登陆
     * @Author 薛有朋
     * @Date 2025/3/26 21:58
     **/
    @PostMapping(value = "/login")
    public Result<UserLoginSuccessVo> login(@RequestBody UserLoginDto userLoginDto){
        UserLoginSuccessVo userLoginSuccessVo = userInfoService.login(userLoginDto);
        return Result.ok(userLoginSuccessVo);
    }

    /**
     * 用户退出
     * @Author 薛有朋
     * @Date 2025/3/28 19:03
     **/
    @GetMapping(value = "/logout")
    public Result logout(@RequestHeader String token){
        userInfoService.logout(token);
        return Result.ok();
    }
}
